<?php
// vim: fdm=marker
/**
 * 文件同步
 * 本脚本只能在jail中以root用户运行，因为会用到root的证书登陆远程服务器
 */

$masterRootDir = '/web/zlink/';
$slaveRootDir  = '/web/zlink/';
$slaveServer = [    
    ['ip' => '61.160.210.29',   'port' => '8011', 'user' => 'www'],
];
$cmd = "/usr/local/bin/rsync -av --delete --exclude 'Runtime/' --exclude 'ck/Log/'";

foreach($slaveServer as $v) {
    $tmpCmd = $cmd . " -e 'ssh -p {$v['port']}' {$masterRootDir} {$v['user']}@{$v['ip']}:{$slaveRootDir}";
    exec($tmpCmd, $r);
    echo implode('|', $v) . '=' . var_export($r, true) . PHP_EOL;
}
